package com.example.springbooksystem.config;

import com.example.springbooksystem.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description：
 *
 * @author: zxj
 * @date: 2024-01-29
 * @time: 15:15:35
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    // 自定义拦截器对象
    @Autowired
    private LoginInterceptor loginInterceptor;

    // 定义排除的路径
    private static List<String> excludePath = Arrays.asList(
            "/user/login",
            "/css/**",
            "/js/**",
            "/pic/**",
            "/**/*.html",
            "/test/**"
    );

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor) // 注册自定义拦截器对象
                .addPathPatterns("/**") // 设置拦截器请求的路径
                .excludePathPatterns(excludePath); // 排除登录路径, 登录路径不拦截
    }
}
